package org.UDPcommunication;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class MutilcastReceiveMessageDemo {
    public static void main(String[] args) throws IOException {
        MulticastSocket multicastSocket=new MulticastSocket(10000);
        InetAddress byName = InetAddress.getByName("224.0.0.1");
        multicastSocket.joinGroup(byName);
        DatagramPacket datagramPacket=new DatagramPacket(new byte[1024],1024);
        multicastSocket.receive(datagramPacket);
        int length = datagramPacket.getLength();
        byte[] data = datagramPacket.getData();
        String hostAddress = datagramPacket.getAddress().getHostAddress();
        System.out.println(new String(data,0,length));
        System.out.println(hostAddress);
        multicastSocket.close();
    }
}
